package com.zhangxin.ch1;

import java.io.BufferedInputStream;
import java.util.Scanner;
//10
//49 59 88 37 98 97 68 54 31 3
public class QuickSort {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        quickSort(arr, 0, n - 1);
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    private static void quickSort(int[] arr, int left, int right) {
        if (left >= right) {
            return;
        }

        int i = left - 1;
        int j = right + 1;
        int curNumber = arr[left];
        while (i < j) {
            do {
                ++i;
            } while (arr[i] < curNumber);
            do {
                --j;
            } while (arr[j] > curNumber);
            if (i < j) {
                swap(arr, i, j);
            }
        }
        quickSort(arr, left, j);
        quickSort(arr, j + 1, right);
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}
